﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using DacSanMienTayOBJ;

public partial class Proccess_ProccessLockAndUnlockProduct : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LockUnlockProduct();
    }

    private void LockUnlockProduct()
    {
        try
        {
            //int modId = (int)Session["ModId"];
            int productID = int.Parse(Request["productID"]);
            string type = Request["type"];
            int vt = int.Parse(Request["vt"]);
            StringBuilder builder = new StringBuilder();
            if (type == "lock")
            {
                bool rs = ProductBusiness.UpdateProductVisible(productID, 0, ConnectionType.AdminConnection);
                if (rs)
                {
                    Product product = ProductBusiness.GetProductDetail(productID, ConnectionType.AdminConnection);
                    string productName = product.ProductName;
                    string imagePath = Utility.modHost + "/" + product.ProductImage;
                    bool checkLocked = false;


                    string statusAdv = "";
                    if (product.IsVisble == 0)
                    {
                        statusAdv = "Đang bị khóa";
                        checkLocked = false;
                    }
                    else if (product.IsVisble == 1)
                    {
                        statusAdv = "Đang active";
                        checkLocked = true;
                    }
                    string description = product.ContentProduct;
                    if (description != "")
                    {
                        //  description = HttpUtility.HtmlDecode(description);
                    }
                    string realPrice = "0";
                    try
                    {
                        realPrice = string.Format("{0:0,0},VND", product.RealPrice);
                    }
                    catch
                    {

                    }
                    int quantity = 0;
                    try
                    {
                        quantity = product.Quantity;
                    }
                    catch
                    {

                    }

                    string linkProduct = Utility.userHost + "/san-pham/" + product.ProductID + "-" + Utility.sefWord(product.ProductName) + ".html";

                    builder.Append("<td><a href=\"" + linkProduct + "\" target=\"_blank\" style=\"text-decoration:none\">" + productName + "</a></td>");

                    builder.Append("<td><a href=\"" + linkProduct + "\" target=\"_blank\" style=\"text-decoration:none\"><image src=\"" + imagePath + "\" height=\"100px\" width=\"100px\" /> </a></td>");
                    builder.Append("<td>" + realPrice + "</td>");
                    builder.Append("<td>" + quantity + "</td>");
                    builder.Append("<td>" + product.MeasurementUnits + "</td>");

                    builder.Append("<td>");

                    builder.Append("<a href=\"#\" style=\"color:Blue; cursor:pointer\" title=\"" + productName + "\"  onclick=\"ShowInfoProduct('" + product.ProductID + "',this.title,'" + product.OriginalPrice + "','" + product.RealPrice + "','" + product.Quantity + "','" + product.MeasurementUnits + "','" + product.ProductOriginal + "','" + product.ProductGuide + "','" + imagePath + "','" + product.ProductImage + "','" + product.Metakeyword + "')\"> Chỉnh sữa</a>");
                    builder.Append("</td>");
                    builder.Append("<td>");

                    if (checkLocked)
                    {

                        builder.Append("<input type=\"button\" title=\"" + product.ProductID + "\"  value=\"Khóa\" onclick=\"LockAndUnlockProduct(this.title,'lock','" + vt + "')\" />");

                    }
                    else
                    {

                        builder.Append("<input type=\"button\" title=\"" + product.ProductID + "\"  value=\"Mở khóa\" onclick=\"LockAndUnlockProduct(this.title,'unlock','" + vt + "')\" />");

                    }
                    builder.Append("</td>");
                    builder.Append("<td>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + product.ProductID + "','movetop')\">Top</span>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + product.ProductID + "','movebottom')\">bottom</span>");
                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("lockfaile");
                }
            }
            else if (type == "unlock")
            {
                bool rs = ProductBusiness.UpdateProductVisible(productID, 1, ConnectionType.AdminConnection);
                if (rs)
                {
                    Product product = ProductBusiness.GetProductDetail(productID, ConnectionType.AdminConnection);
                    string productName = product.ProductName;
                    string imagePath = Utility.modHost + "/" + product.ProductImage;
                    bool checkLocked = false;


                    string statusAdv = "";
                    if (product.IsVisble == 0)
                    {
                        statusAdv = "Đang bị khóa";
                        checkLocked = false;
                    }
                    else if (product.IsVisble == 1)
                    {
                        statusAdv = "Đang active";
                        checkLocked = true;
                    }
                    string description = product.ContentProduct;
                    if (description != "")
                    {
                        //  description = HttpUtility.HtmlDecode(description);
                    }
                    string realPrice = "0";
                    try
                    {
                        realPrice = string.Format("{0:0,0},VND", product.RealPrice);
                    }
                    catch
                    {

                    }
                    int quantity = 0;
                    try
                    {
                        quantity = product.Quantity;
                    }
                    catch
                    {

                    }

                    string linkProduct = Utility.userHost + "/san-pham/" + product.ProductID + "-" + Utility.sefWord(product.ProductName) + ".html";

                    builder.Append("<td><a href=\"" + linkProduct + "\" target=\"_blank\" style=\"text-decoration:none\">" + productName + "</a></td>");

                    builder.Append("<td><a href=\"" + linkProduct + "\" target=\"_blank\" style=\"text-decoration:none\"><image src=\"" + imagePath + "\" height=\"100px\" width=\"100px\" /> </a></td>");
                    builder.Append("<td>" + realPrice + "</td>");
                    builder.Append("<td>" + quantity + "</td>");
                    builder.Append("<td>" + product.MeasurementUnits + "</td>");

                    builder.Append("<td>");

                    builder.Append("<a href=\"#\" style=\"color:Blue; cursor:pointer\" title=\"" + productName + "\"  onclick=\"ShowInfoProduct('" + product.ProductID + "',this.title,'" + product.OriginalPrice + "','" + product.RealPrice + "','" + product.Quantity + "','" + product.MeasurementUnits + "','" + product.ProductOriginal + "','" + product.ProductGuide + "','" + imagePath + "','" + product.ProductImage + "','" + product.Metakeyword + "')\"> Chỉnh sữa</a>");
                    builder.Append("</td>");
                    builder.Append("<td>");

                    if (checkLocked)
                    {

                        builder.Append("<input type=\"button\" title=\"" + product.ProductID + "\"  value=\"Khóa\" onclick=\"LockAndUnlockProduct(this.title,'lock','" + vt + "')\" />");

                    }
                    else
                    {

                        builder.Append("<input type=\"button\" title=\"" + product.ProductID + "\"  value=\"Mở khóa\" onclick=\"LockAndUnlockProduct(this.title,'unlock','" + vt + "')\" />");

                    }
                    builder.Append("</td>");
                    builder.Append("<td>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + product.ProductID + "','movetop')\">Top</span>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + product.ProductID + "','movebottom')\">bottom</span>");
                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("unlockfaile");
                }
            }
            Response.End();
        }
        catch
        {

        }
    }
}